package kd.bos.openapi.demo.sample.operation.controller;

import kd.bos.openapi.sdk.dto.OrderDto;
import kd.bos.openapi.sdk.exception.APIException;
import kd.bos.openapi.sdk.request.RequestQueryDto;
import kd.bos.openapi.sdk.response.APIResponseDto;
import kd.bos.openapi.sdk.response.ResponseFactory;
import kd.bos.openapi.sdk.response.result.Result;
import kd.bos.openapi.sdk.response.result.ResultCode;
import kd.bos.openapi.demo.sample.operation.service.OrderService;
import kd.bos.openapi.demo.sample.operation.service.impl.OrderServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Deacription 订单对外接口，如前端
 * @author johnzou
 * @date 2022年4月6日
 */
@RestController
@RequestMapping("")
@Slf4j
public class OrderController {

    @Autowired
    private final OrderService orderService = new OrderServiceImpl();

    /**
     * 查询订单
     * @param orderRequestDto
     * @return
     * @throws APIException
     */
    @PostMapping("findOrders")
    public ResponseEntity<Result<APIResponseDto>> findOrdersResponseEntity(RequestQueryDto<OrderDto> orderRequestDto) throws APIException {
        APIResponseDto apiResponseDto = orderService.findOrders(orderRequestDto);
        if(apiResponseDto.getCode().equalsIgnoreCase("0")){
            return ResponseFactory.success(apiResponseDto);
        }
        return ResponseFactory.fail(ResultCode.getResultCodeByCode(apiResponseDto.getCode()));
    }

}
